<?php

/**
 * @see Zend_Validate_Abstract
 */
require_once 'Zend/Validate/Abstract.php';


class Core_Validate_EmailExists extends Zend_Validate_Abstract
{
	/**
	 * Validation failure message key for when the value is not unique.
	 */
	const DOES_NOT_EXIST = 'emailDoesNotExist';

	/**
	 * Validation failure message template definitions
	 *
	 * @var array
	 */
	protected $_messageTemplates = array(
		self::DOES_NOT_EXIST	=> "We were unable to find this email address."
	);

	/**
	 * Defined by Zend_Validate_Interface
	 *
	 * Returns true if and only if $value contains only alphabetic and digit characters
	 *
	 * @param  string $value
	 * @return boolean
	 */
	public function isValid($value)
	{
		$this->_setValue( $value );
		
		
		$user = $userModel->findUserByEmail( $value );
		
		if ( !empty($user) )
		{
			return true;
		}
		
		$this->_error(self::DOES_NOT_EXIST);
		return false;
	}

}
